<template>
  <div class="layout_createdBill booking-detail">
    <!-- <div v-if="o_type>3">
      <div class="aicon" v-if="o_type<6">秒杀</div>
      <div class="aicon" v-else>全款</div>
      <div class="row">
        <label>项 目 名 称：</label>
        <input type="text" v-model="o_project_name" readonly />
      </div>
      <div class="row">
        <label>项 目 金 额：</label>
        <input type="text" v-model="o_project_price" readonly />
      </div>
      <div class="jiange"></div>
    </div>-->
    <div class="row">
      <label>医&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;院：</label>
      <cube-select v-model="hospital" :options="hospital_list" :disabled="true" placeholder="请选择医院"></cube-select>
      <Icon type="ios-arrow-right" class="select-icon"></Icon>
    </div>
    <div class="row">
      <label>客 户 姓 名：</label>
      <input type="text" v-model="o_username" readonly />
    </div>
    <div class="row">
      <label>客 户 手 机：</label>
      <input type="tel" v-model="o_tel" @change="get_service()" maxlength="11" readonly />
    </div>
    <div class="row" v-show="false">
      <label>身 份 认 证：</label>
      <input type="text" v-model="o_identify" maxlength="18" />
    </div>
    <div class="row type">
      <label>报 单 类 型：</label>
      <div style="width:72%">
        <cube-radio-group v-model="form_type" :options="formTypeOptions" :horizontal="true" />
      </div>
    </div>

    <!-- <div class="row type">
            <label>付款方式：</label>
            <cube-radio-group
                v-model="paymentId"
                :options="paymentIdOptions"
                :horizontal="true"
                style="flex-grow:1;font-size:80%;"
            />

    </div>-->
    <!-- 暂时隐藏分期选项 -->
    <!-- <div class="row type" v-if="paymentId == 2">
            <label>贷 款 平 台：</label>
            <cube-radio-group v-model="loadPlatform"
                                :options="loadPlatformOptions"
                                :horizontal="true" />
        </div>
        <div class="row" v-if="paymentId == 2">
            <label>贷 款 期 数：</label><input type="text"
                v-model="loadStage">
    </div>-->

    <!-- <div class="row type">
        <label>活 动 名 称：</label>
        <cube-radio-group v-model="sales_type" :options="sales_typeOP" :horizontal="true" />
    </div>-->
    <!-- <div class="row" v-if="form_type_tf"> -->
    <div class="row">
      <label>活 动 名 称：</label>
      <cube-select
        v-model="sales_type"
        :options="form_type_tf?sales_typeOP:sales_typect"
        placeholder="请选择"
        :disabled="disabled"
      ></cube-select>

      <Icon type="ios-arrow-right" class="select-icon"></Icon>
    </div>

    <div class="row">
      <label>消费总金额：</label>
      <input
        type="tel"
        v-model="total_price"
        maxlength="10"
        @input="change_money()"
        :disabled="disabled"
      />
    </div>

    <!-- <div class="row" v-if="form_type==0">
            <label>扣除杂费金额：</label>
            <input type="tel" v-model="orderAmount" @change.prevent="change_money()" maxlength="10" />
            <p class="tip">注：扣除杂费金额=消费总金额-成本</p>
        </div>
        <div class="row" v-if="form_type==1">
            <label>扣除杂费金额：</label>
            <input type="tel" v-model="orderAmount" @change.prevent="change_money()" maxlength="10" 
            placeholder="请输入扣除杂费金额"/>
        </div>
        <div class='row' v-if="saleFlag">
            <p style="color: #ccc;line-height: 24px;margin: 10px 0;">消费总金额及奖励总金额请填写除2020元中额外升单金额若没有额外升单消费，仅消费2020活动中项目，则消费总金额、奖励总金额填写0元</p>
    </div>-->

    <!-- V1.8.7 -->
    <!-- 付款方式 -->
    <div class="row border_no">
      <label>付 款 方 式：</label>
      <div class="right paddingsx">
        <!-- <cube-checkbox-group
                    v-model="paySelected"
                    :options="payOptions"
                    :hollow-style="true"
        />-->
        <cube-checkbox-group
          v-model="paySelected"
          v-if="is_whole_project==1"
          cancel-checked="cancelChecked"
        >
          <div class="border_yes" v-if="water_info.gold_coin>0">
            <div data-v-fa3cbdfc data-pos="left" class="cube-checkbox cube-checkbox_checked">
              <label class="cube-checkbox-wrap border-bottom-1px">
                <input type="checkbox" class="cube-checkbox-input" />
                <span class="cube-checkbox-ui cubeic-round-border">
                  <i class="cubeic-right"></i>
                </span>
                <span class="cube-checkbox-label">
                  <i data-v-fa3cbdfc>金&emsp;&emsp;币</i>
                </span>
              </label>
            </div>
            <div class="num">{{gold_coin}}</div>
          </div>
          <div class="border_yes" v-if="water_info.platform_money>0">
            <div data-v-fa3cbdfc data-pos="left" class="cube-checkbox cube-checkbox_checked">
              <label class="cube-checkbox-wrap border-bottom-1px">
                <input type="checkbox" class="cube-checkbox-input" />
                <span class="cube-checkbox-ui cubeic-round-border">
                  <i class="cubeic-right"></i>
                </span>
                <span class="cube-checkbox-label">
                  <i data-v-fa3cbdfc>平台已支付现金</i>
                </span>
              </label>
            </div>
            <div class="num">{{water_info.platform_money}}</div>
          </div>
        </cube-checkbox-group>
        <cube-checkbox-group v-model="paySelected" v-else>
          <div>
            <cube-checkbox option="3" v-if="accountOpenStatus == 2">
              <i>线上收款</i>
            </cube-checkbox>
            <cube-checkbox :option="{disabled: true}" v-else>
              <i>线上收款</i>
            </cube-checkbox>
            <cube-input
              v-if="pay003"
              v-model="online_money"
              @change="moneyRE(online_money,'online_money')"
              placeholder="该金额为线上收款平台收款金额"
            ></cube-input>
          </div>
          <!-- <div>
            <cube-checkbox option="3">
              <i>线上收款</i>
            </cube-checkbox>
            <cube-input
              v-if="pay003"
              v-model="online_money"
              @change="moneyRE(online_money,'online_money')"
              placeholder="该金额为线上收款平台收款金额"
            ></cube-input>
          </div>-->

          <div>
            <cube-checkbox option="1">
              <i>现&emsp;&emsp;金</i>
            </cube-checkbox>
            <cube-input
              v-if="pay001"
              v-model="own_money"
              @change="moneyRE(own_money,'own_money')"
              placeholder="该金额为医院POS机收款金额"
            ></cube-input>
          </div>
          <div>
            <cube-checkbox option="2">
              <i>分&emsp;&emsp;期</i>
            </cube-checkbox>
            <cube-input
              v-if="pay002"
              v-model="stage_money"
              @change="moneyRE(stage_money,'stage_money')"
              placeholder="该金额为医院贷款金额"
            ></cube-input>
          </div>
          <div class="relative" v-if="gold_status==1&&user_gold!=0">
            <cube-checkbox option="4">
              <i>金&emsp;&emsp;币</i>
            </cube-checkbox>
            <div v-if="pay004">
              <span class="jybspan">当前可用金币{{user_gold}}</span>
              <cube-input
                @input="change_moneys()"
                v-model="gold_coin"
                placeholder="请输入使用的金币数量，金币无奖励"
              ></cube-input>
              <div class="yzmdiv">
                <cube-input style="width:60%" v-model="code" placeholder="请输入获取的验证码"></cube-input>
                <span @click="sendCode()" :class="{ 'disableds': isActive }" class="yzm">{{codeTxt}}</span>
              </div>
            </div>
          </div>
        </cube-checkbox-group>
      </div>
    </div>

    <!-- 1.8.9 -->
    <div class="row" v-if="form_type==0">
      <label>杂费金额：</label>
      <input
        type="tel"
        placeholder="请输入杂费金额"
        v-model="orderAmount"
        :disabled="disabled"
        @input="change_money()"
        maxlength="10"
      />
    </div>
    <div class="row" v-if="form_type==1">
      <label>杂费金额：</label>
      <input
        type="tel"
        v-model="orderAmount"
        @input="change_money()"
        maxlength="10"
        :disabled="disabled"
        placeholder="请输入杂费金额"
      />
    </div>
    <div class="row" v-if="saleFlag">
      <p
        style="color: #ccc;line-height: 24px;margin: 10px 0;"
      >消费总金额及奖励总金额请填写除2020元中额外升单金额若没有额外升单消费，仅消费2020活动中项目，则消费总金额、奖励总金额填写0元</p>
    </div>

    <div class="row" v-if="form_type!=1">
      <label>奖励总金额：</label>
      <input type="tel" v-model="jlzje" readonly />
    </div>
    <div class="row" v-if="form_type==1">
      <label>奖励金额(无补贴)：</label>
      <input style="width:40%" type="tel" v-model="jlzje" readonly />
    </div>
    <!-- 1.8.9 -->

    <div class="row" v-if="zfpaydiv">
      <label>杂费付款方式：</label>
      <div>
        <cube-radio-group :horizontal="true">
          <cube-radio v-if="pay003" option="线上收款" v-model="zfpay"></cube-radio>
          <cube-radio v-if="pay001" option="现金" v-model="zfpay"></cube-radio>
          <cube-radio v-if="pay002" option="分期" v-model="zfpay"></cube-radio>
        </cube-radio-group>
      </div>
    </div>
    <!-- <button @click="testbtn()">提交</button> -->
    <!-- V1.8.7 -->

    <!-- 2019.08.16 产品又要求去掉 -->
    <!-- <div class="row">
        <label>预计现金补贴：</label><input type="tel"
                v-model="cash_allowance"
                maxlength="10">
        </div>
        <div class="row">
        <label>预计积分补贴：</label><input type="tel"
                v-model="integral_allowance"
                maxlength="10">
    </div>-->

    <!-- <div class="row credit">
        <label>开启积分支付：</label>
        <cube-switch v-model="isopen"
                    :disabled="orderAmount==''||o_tel==''"></cube-switch>
        </div>
        <div class="row"
            v-if="isopen">
        <label>本单抵扣积分：</label><input type="text"
                v-model="credit"
                maxlength="10"
                disabled>
        </div>
        <div class="row check_num"
            v-if="isopen">
        <label>验证码：</label><input type="tel"
                v-model="check_num"
                maxlength="6">
        <div class="get-msg"
            @click="get_check()">{{btn_msg}}</div>
    </div>-->
    <div class="row" v-if="isopen">
      <label>实 付 金 额：</label>
      <input type="text" v-model="pay_num" />
    </div>
    <div class="row" v-if="paymentId != 3 ">
      <!-- :disabled="disabled" -->
      <cube-button @click="is_whole_project == 1?'':selectTime()" class="time-btn">
        支 付 时 间：
        <span class="orderDate">{{orderDate}}</span>
        <Icon type="ios-arrow-right" class="select-icon"></Icon>
      </cube-button>
    </div>
    <div class="row type">
      <label>客 户 类 型：</label>
      <cube-radio-group v-model="selected" :options="options" :horizontal="true" />
    </div>
    <div class="row" v-if="selected==1">
      <label>上 级 姓 名：</label>
      <input type="text" v-model="server_name" disabled />
    </div>
    <div class="row" v-if="selected==1">
      <label>上 级 手 机：</label>
      <input type="text" v-model="server_username" disabled />
    </div>
    <div class="row">
      <label>咨 询 师：</label>
      <cube-select v-model="consultant_id" :options="consultant_list" placeholder="请选择咨询师"></cube-select>

      <Icon type="ios-arrow-right" class="select-icon"></Icon>
    </div>
    <div class="row">
      <a href="#" class>
        完 成 项 目：0
        <!-- <span v-text="programNum"></span> -->
        <!-- <Icon type="ios-arrow-right"></Icon> -->
      </a>
    </div>
    <div class="text">
      <span>备注：</span>
      <mt-field label placeholder type="textarea" rows="4" v-model="o_introduction"></mt-field>
    </div>
    <div class="gray"></div>
    <div class="uploadMoudle" v-if="paymentId != 3 ">
      <p>上传图片（最多上传3张）：</p>
      <cube-upload
        :action="action"
        :max="3"
        @files-added="filesAddedOrder"
        @file-success="fileSuccessOrder"
        @file-removed="fileRemovedOrder"
      />
    </div>
    <!-- <cube-textarea v-model="o_introduction" :maxlength="255" ></cube-textarea> -->
    <button @click="bill_confirm()">提交</button>
    <!--:disabled="isdisabled"-->
    <div class="mask" @click="close_confirm()" v-if="confirm">
      <div class="content">
        <div class="header">确认流水单信息</div>
        <div class="main">
          <!-- <div class="tip" v-if="hospital_status !== 2 &&accountOpenStatus != 2">
          提示：当前医院未录入入驻信息，请联系商务中心进行入驻信息录入，截止12月1日还未录入的医院将无法申报流水单。</div>-->
          <div class="item">客户姓名：{{o_username}}</div>
          <div class="item item-line">客户手机：{{o_tel}}</div>
          <div class="item" v-if="selected==1">上级姓名：{{server_name}}</div>
          <div class="item" v-if="selected==1">上级手机：{{server_username}}</div>
        </div>
        <div class="bottom" @click.stop="billSubmit()">确认</div>
      </div>
    </div>
  </div>
</template>
<script >
import { Toast } from "mint-ui";
import api from "../../assets/js/api";
let timer;
export default {
  name: "createdBill",
  data() {
    return {
      form_type_tf: true,
      order_id: 0,
      o_type: 0,
      o_project_name: "", //全款项目名称
      o_project_price: "", //全款项目价格
      o_identify: "", //身份证号

      total_price: "", //消费总金额
      // reward_price: "",     //扣除杂费金额
      cash_allowance: "", //现金补贴
      integral_allowance: "", //积分补贴
      img: "", //流水单图片 最多上传三张

      order_sn: "", //流水账单
      orderAmount: "", //付款金额
      orderDate: "", //刷卡时间
      orderPaytype: "", //流水单付款方式
      o_username: "", //用户姓名
      o_tel: "",
      programNum: "",
      o_introduction: "", //备注
      isdisabled: false,
      hospital_list: [],
      hospital: "",
      hospital_status: 0, //医院入驻开户状态（0：未开户,1：待审核,2: 开户成功,3：开户失败） -再改意思打死你

      service: "",
      selected: 1,
      pay_num: "",
      options: [
        {
          label: "渠道",
          value: 1
        },
        {
          label: "直客",
          value: 2
        }
      ],
      server_username: "",
      server_name: "",
      isopen: false,
      credit: "",
      check_num: "",
      btn_msg: "获取验证码",
      num: 60,
      credit_all: "",
      confirm: false,

      paymentId: 1, //付款方式 自费=>1 分期=>2 线上收款=>3
      paymentIdOptions: [
        {
          label: "现金",
          value: 1,
          id: "own_money"
        },
        {
          label: "分期",
          value: 2,
          id: "stage_money"
        },
        {
          label: "线上收款",
          value: 3,
          id: "online_money"
        }
        // {
        //   label: "",
        //   value: 3,
        //   id: "online_money"
        // }
      ],
      loadPlatform: 0, //贷款平台 0=>未选择, 1=>易美信, 2=>其他
      loadPlatformOptions: [
        {
          label: "易美信",
          value: 1
        },
        {
          label: "其他",
          value: 2
        }
      ],
      loadStage: 0, //贷款期数

      //咨询师名称
      consultant_id: 0,
      //咨询师列表 从接口获取
      consultant_list: [],

      //上传组件使用
      action: {
        // 正式服
        target: "https://act.yuepinyuemei.com/api/upload/img",
        data: {
          dirPath: "order"
        }
      },
      paySelected: [], //选中付款方式
      pay001: false, //现金flag
      pay002: false, //分期flag
      pay003: false, //线上收款flag
      zfpay: "0", //杂费付款方式
      zfpaydiv: false, //杂费付款方式显影
      online_money: null, //线上收款
      own_money: null, //现金
      stage_money: null, //分期
      accountOpenStatus: null, //开户状态， 0未开户，1.待审核 2：开户成功 3：开户失败
      currentReimbursementRatio: null, //美美咖报单回款比率
      normalReimbursementRatio: null, //传统报单回款比率
      formTypeOptions: [
        {
          label: "美美咖报单",
          value: 0
        },
        {
          label: "传统报单",
          value: 1
        }
      ],
      form_type: 0, //报单类型，0 美美咖报单，1 传统报单
      currentReimbursementRatio: null, //医院回款比例
      sales_type: "0",
      saleFlag: false,
      sales_typeOP: [
        {
          name: "未参加",
          text: "未参加",
          value: "0"
        },
        // {
        //   name: "2020定金全额补",
        //   text: "2020定金全额补",
        //   value: "2020"
        // },
        {
          name: "2020定金抵扣活动",
          text: "2020定金抵扣活动",
          value: "3"
        }
      ],
      sales_typect:[ //传统报单保定的活动选项
         {
          name: "未参加",
          text: "未参加",
          value: "0"
        },
      ],
      // 1.8.9
      codeTxt: "获取验证码",
      isActive: false,
      codeNum: 60,
      gold_status: 0, // 是否支持金币抵扣0否1是
      pay004: false, //金银币flag
      user_gold: 0, //用户账户的金币数量
      jlzje: 0, //奖励总金额
      gold_coin: 0, //使用金币
      code: null, //验证码
      settlement_type: 0, //结算模式
      online_cash_checked: false,
      disabled: false,
      is_whole_project: 0,
      water_info: {}
    };
  },
  methods: {
    check_online_cash() {},
    // 金银币chang事件
    change_moneys() {
      this.jlzje = this.total_price - this.orderAmount;
      if (this.jlzje >= 0) {
        this.jlzje = this.total_price - this.orderAmount;
      } else {
        this.jlzje = 0;
      }
      if (this.gold_coin > this.user_gold) {
        this.gold_coin = 0;
        Toast({
          message: "可使用金币数量不足",
          position: "bottom",
          duration: 2000
        });
      }
      if (this.gold_coin) {
        this.gold_coin = parseInt(this.gold_coin);
      } else {
        this.gold_coin = "";
      }
      console.log(this.gold_coin);
    },
    //获取方法
    codeFn() {
      let data = {
        username: this.o_tel
      };
      this.axios
        .post("/api/butler/send_gold_code", data)
        .then(msg => {
          if (msg.data.code == 200) {
            Toast({
              message: "提交成功",
              position: "bottom",
              duration: 2000
            });
            console.log("msg", msg);
          } else if (msg.data.code == 250) {
            Toast({
              message: "登录过期，请重新登陆",
              position: "bottom",
              duration: 2000
            });
            this.$router.push("/login");
            return false;
          } else {
            Toast({
              message: msg.data.msg,
              position: "bottom",
              duration: 2000
            });
          }
        })
        .catch(error => {
          load.hide();
          Toast({
            message: "请求失败，请稍后重试",
            position: "bottom",
            duration: 2000
          });
        });
    },
    // 获取验证码
    sendCode() {
      let that = this;
      this.codeFn();
      let times = setInterval(function() {
        if (that.codeNum) {
          that.codeNum--;
          that.isActive = true;
          that.codeTxt = that.codeNum + "s重新发送";
          console.log(123);
        } else {
          that.codeNum = 6;
          that.codeTxt = "重发验证码";
          that.isActive = false;
          console.log(321);
          clearInterval(times);
        }
      }, 1000);
    },
    // 测试按钮
    testbtn() {
      let jez, xfz, xj, gxje, fkfs;
      // 录入的金额之和
      if (this.gold_coin || this.water_info.platform_money) {
        jez =
          Number(this.online_money) +
          Number(this.own_money) +
          Number(this.stage_money) +
          Number(this.gold_coin) +
        Number(this.water_info.platform_money);
      }else{
         jez =
        Number(this.online_money) +
        Number(this.own_money) +
        Number(this.stage_money);
      }

      // 消费总金额
      xfz = Number(this.total_price);
      // 消费总金额-扣除杂费金额
      xj = Number(this.total_price) - Number(this.orderAmount);
      //获取勾选付款方式填写的金额
      this.paymentIdOptions.forEach(e => {
        if (e.label == this.zfpay) {
          fkfs = e.label;
          gxje = this[e.id];
        }
      });
      let xzjb = this.paySelected.join(" ");
      if (Number(xzjb) == 4 && Number(this.orderAmount) > 0) {
        Toast({
          message: `金币不允许支付杂费，请选择其余付款方式支付`,
          position: "bottom",
          duration: 2000
        });
        this.isdisabled = false;
        return false;
      } else if (
        this.accountOpenStatus == 2 &&
        this.form_type == 0 &&
        this.online_money > 0 &&
        Number(this.currentReimbursementRatio) == 0
      ) {
        Toast({
          message: `医院回款比率获取异常，请稍后再试`,
          position: "bottom",
          duration: 2000
        });
      } else if (
        this.accountOpenStatus == 2 &&
        this.form_type == 1 &&
        this.online_money > 0 &&
        Number(this.normalReimbursementRatio) == 0
      ) {
        Toast({
          message: `医院回款比率获取异常，请稍后再试`,
          position: "bottom",
          duration: 2000
        });
      } else if (this.accountOpenStatus != 2 && this.online_money > 0) {
        Toast({
          message: `当前医院未开户，不允许使用线上收款方式`,
          position: "bottom",
          duration: 2000
        });
      } else if (this.pay003 && !this.online_money) {
        Toast({
          message: "线上收款-已勾选付款方式金额为空，请填写后再提交",
          position: "bottom",
          duration: 2000
        });
      } else if (this.pay001 && !this.own_money) {
        Toast({
          message: "pos未填写-已勾选付款方式金额为空，请填写后再提交",
          position: "bottom",
          duration: 2000
        });
      } else if (this.pay002 && !this.stage_money) {
        Toast({
          message: "医院未填写-已勾选付款方式金额为空，请填写后再提交",
          position: "bottom",
          duration: 2000
        });
      } else if (this.zfpaydiv && !this.zfpay) {
        Toast({
          message: "当前流水单存在杂费，请选择杂费付款方式",
          position: "bottom",
          duration: 2000
        });
        // console.log(Number(this.online_money)+Number(this.own_money)+Number(this.stage_money))
      } else if (jez != xfz) {
        Toast({
          message: "各付款方式金额之和不等于消费总金额，请重新输入",
          position: "bottom",
          duration: 2000
        });
      }
      // if(gxje<xj){
      //     Toast({
      //         message: `${fkfs}填写的金额小于杂费金额，请重新输入`,
      //         position: "bottom",
      //         duration: 2000
      //     });
      // }
      else if (gxje < this.orderAmount) {
        Toast({
          message: `${fkfs}填写的金额小于杂费金额，请重新输入`,
          position: "bottom",
          duration: 2000
        });
      }

      let extraType = "0";
      switch (this.zfpay) {
        case "现金":
          extraType = "1";
          break;
        case "分期":
          extraType = "2";
          break;
        case "线上收款":
          extraType = "3";
          break;
      }
      if (this.own_money == null) {
        this.own_money = 0;
      }
      if (this.stage_money == null) {
        this.stage_money = 0;
      }
      if (this.online_money == null) {
        this.online_money = 0;
      }
      let data = {
        own_money: String(this.own_money),
        stage_money: String(this.stage_money),
        online_money: String(this.online_money),
        extra_type: String(extraType),
        payment_ids: this.paySelected,
        form_type: this.form_type,
        sales_type: String(this.sales_type)
      };
      // console.log(666,this.paySelected.indexOf("3"))
      if (
        !(this.paySelected.length == 1 && this.paySelected.indexOf("3") != -1)
      ) {
        // console.log(data, "必填");
      } else {
        // console.log(data, "非必填");
      }
    },
    // 金额整数数校验
    moneyRE(num, str) {
      if (Number(num) < 0 || isNaN(num)) {
        this[str] = null;
      } else {
        if (num) {
          this[str] = parseInt(num);
        } else {
          this[str] = null;
        }
      }
    },
    //获取医院是否开户状态
    getHospitalInfo() {
      this.axios
        .post("api/butler/hospital_info", {
          hospital_id: this.hospital
        })
        .then(res => {
          // console.log(res.data.data)
          let resData = res.data.data;
          this.accountOpenStatus = resData.accountOpenStatus;
          this.currentReimbursementRatio = resData.currentReimbursementRatio;
          this.normalReimbursementRatio = resData.normalReimbursementRatio;
          this.settlement_type = resData.settlementType;
          console.log(this.settlement_type);
        })
        .catch(err => {
          console.log(err);
        });
    },
    //获取详情
    getOrderInfo() {
      this.axios
        .post("api/butler/order/info", {
          order_id: this.order_id
        })
        .then(result => {
          let res = result.data;
          if (res.code == 250) {
            this.$router.push("/login");
            return false;
          }
          if (res.code != 200) {
            return false;
          }
          this.o_type = res.data.type;
          this.o_project_name = res.data.project_name;
          this.o_project_price = res.data.project_price; //全款项目价格
          this.o_username = res.data.user.realname; //用户姓名
          this.o_tel = res.data.user.username; //用户手机号
          if (this.o_tel) {
            this.get_service();
          }
          this.is_whole_project = res.data.is_whole_project;
          this.hospital = res.data.hospital_id; //医院id
          console.log(55223,this.hospital)
          this.o_identify = res.data.user.identify; //身份证号
          this.consultant_list = res.data.consultant_list; //咨询师列表
          this.hospital_status = res.data.hospital_status; //医院状态
          this.gold_status = res.data.gold_status; //是否支持金币抵扣
          this.user_gold = res.data.user_gold; // 账户金币
          // this.settlement_type = res.data.settlement_type  //结算模式

          // console.log(this.consultant_list);
          this.getHospitalInfo();
          // 双20代码
          // console.log("is_whole_allowance",res.data.is_whole_allowance)

          if (res.data.is_whole_project == 1) {
            this.disabled = true;
            this.form_type = -1;
            this.selected = 0;
            this.water_info = res.data.water_info;
            if (
              this.water_info.gold_coin > 0 &&
              this.water_info.platform_money <= 0
            ) {
              this.paySelected = ["4"];
            } else if (
              this.water_info.platform_money > 0 &&
              this.water_info.gold_coin <= 0
            ) {
              this.paySelected = ["5"];
            } else {
              this.paySelected = ["4", "5"];
            }
            this.gold_coin = this.water_info.gold_coin;
            this.orderAmount = this.water_info.extra_money.toString();
            this.total_price = this.water_info.total_price.toString();
            this.orderDate = this.water_info.pay_time;
            this.jlzje = this.water_info.all_price;
          }
          // 是否参与全额补贴活动 1 参与 0 不参与
          if (res.data.is_whole_allowance == 1) {
            this.sales_typeOP.push({
              name: "2020服务商招商活动全额补",
              text: "2020服务商招商活动全额补",
              value: "1"
            });
          }
          if (res.data.is_nine == 1) {
            this.sales_typeOP.push({
              name: "超级卖手90%补贴",
              text: "超级卖手90%补贴",
              value: "2"
            });
          }
          // 2000定金9折活动
          if (res.data.is_deposit_nine == 1) {
            this.sales_typeOP.push({
              name: "2000定金九折补贴",
              text: "2000定金九折补贴",
              value: "4"
            });
            
            this.sales_typect.push({
              name: "2000定金九折补贴",
              text: "2000定金九折补贴",
              value: "4"
            });
          }
        })
        .catch(err => {
          console.log(err);
        });
    },

    getdata(value) {},
    close_confirm() {
      this.confirm = false;
      this.isdisabled = false;
    },
    showDatePicker() {
      if (!this.datePicker) {
        this.datePicker = this.$createDatePicker({
          title: "日期",
          min: new Date(
            new Date().getFullYear(),
            new Date().getMonth(),
            new Date().getDate()
          ),
          max: new Date(2030, 12, 31),
          value: new Date(),
          onSelect: this.selectHandle,
          onCancel: this.cancelHandle
        });
      }
      this.datePicker.show();
    },
    selectHandle(date, selectedVal, selectedText) {
      this.orderDate = selectedText.join("-");
    },
    billSubmit(value) {
      // ,this.orderAmount.trim()

      let jez, xfz, xj, gxje, fkfs;
      // 录入的金额之和
      if (this.gold_coin && !this.water_info.platform_money) {
        jez =
          Number(this.online_money) +
          Number(this.own_money) +
          Number(this.stage_money) +
          Number(this.gold_coin) 
      }else if (this.gold_coin && this.water_info.platform_money) {
        jez =
          Number(this.online_money) +
          Number(this.own_money) +
          Number(this.stage_money) +
          Number(this.gold_coin) +
        Number(this.water_info.platform_money);
      }else{
         jez =
        Number(this.online_money) +
        Number(this.own_money) +
        Number(this.stage_money);
      }
      // 消费总金额
      xfz = Number(this.total_price);
      // 消费总金额-扣除杂费金额
      xj = Number(this.total_price) - Number(this.orderAmount);
      //获取勾选付款方式填写的金额
      this.paymentIdOptions.forEach(e => {
        if (e.label == this.zfpay) {
          fkfs = e.label;
          gxje = this[e.id];
        }
      });

      this.isdisabled = true;
      /* 身份证验证已去掉V1.8.7 */
      /* if (this.o_identify.trim() == "") {
                Toast({
                    message: "请填写身份证号",
                    position: "bottom",
                    duration: 2000
                });
                this.isdisabled = false;
                return false;
            }  */
      let xzjb = this.paySelected.join(" ");
      if (Number(xzjb) == 4 && Number(this.orderAmount) > 0) {
        Toast({
          message: `金币不允许支付杂费，请选择其余付款方式支付`,
          position: "bottom",
          duration: 2000
        });
        this.isdisabled = false;
        return false;
      } else if (
        this.accountOpenStatus == 2 &&
        this.form_type == 0 &&
        this.online_money > 0 &&
        Number(this.currentReimbursementRatio) == 0
      ) {
        Toast({
          message: `医院回款比率获取异常，请稍后再试`,
          position: "bottom",
          duration: 2000
        });
      } else if (
        this.accountOpenStatus == 2 &&
        this.form_type == 1 &&
        this.online_money > 0 &&
        Number(this.normalReimbursementRatio) == 0
      ) {
        Toast({
          message: `医院回款比率获取异常，请稍后再试`,
          position: "bottom",
          duration: 2000
        });
      } else if (this.accountOpenStatus != 2 && this.online_money > 0) {
        Toast({
          message: `当前医院未开户，不允许使用线上收款方式`,
          position: "bottom",
          duration: 2000
        });
      }

      // if(this.pay003&&!this.online_money){
      //     Toast({
      //         message: "已勾选付款方式金额为空，请填写后再提交",
      //         position: "bottom",
      //         duration: 2000
      //     });
      //     this.isdisabled = false;
      //     return false;
      // }else if(this.pay001&&!this.own_money){
      //     Toast({
      //         message: "已勾选付款方式金额为空，请填写后再提交",
      //         position: "bottom",
      //         duration: 2000
      //     });
      //     this.isdisabled = false;
      //     return false;
      // }else if(this.pay002&&!this.stage_money){
      //     Toast({
      //         message: "已勾选付款方式金额为空，请填写后再提交",
      //         position: "bottom",
      //         duration: 2000
      //     });
      //     this.isdisabled = false;
      //     return false;
      // }
      // else
      else if (this.zfpaydiv && !this.zfpay) {
        Toast({
          message: "当前流水单存在杂费，请选择杂费付款方式",
          position: "bottom",
          duration: 2000
        });
        this.isdisabled = false;
        return false;
      } else if (jez != xfz) {
        Toast({
          message: "各付款方式金额之和不等于消费总金额，请重新输入",
          position: "bottom",
          duration: 2000
        });
        this.isdisabled = false;
        return false;
      }
      // if(gxje<xj){
      //     Toast({
      //         message: `${fkfs}填写的金额小于杂费金额，请重新输入`,
      //         position: "bottom",
      //         duration: 2000
      //     });
      //     this.isdisabled = false;
      //     return false;
      // }
      else if (gxje < this.orderAmount) {
        Toast({
          message: `${fkfs}填写的金额小于杂费金额，请重新输入`,
          position: "bottom",
          duration: 2000
        });
        this.isdisabled = false;
        return false;
      } else if (this.hospital == "") {
        Toast({
          message: "请选择医院",
          position: "bottom",
          duration: 2000
        });
        this.isdisabled = false;
        return false;
      } else if (this.o_username.trim() == "") {
        Toast({
          message: "请填写客户姓名",
          position: "bottom",
          duration: 2000
        });
        this.isdisabled = false;
        return false;
      } else if (this.o_tel.trim() == "") {
        Toast({
          message: "请填写客户手机号",
          position: "bottom",
          duration: 2000
        });
        this.isdisabled = false;
        return false;
        // } else if (this.orderPaytype.trim() == "") {
        //   Toast({
        //     message: "请填写付款方式",
        //     position: "bottom",
        //     duration: 2000
        //   });
        //   this.isdisabled = false;
        //   return false;

        // } else if (this.paymentId == 2 && this.loadStage == 0) {
        //   Toast({
        //     message: "请输入贷款期数",
        //     position: "bottom",
        //     duration: 2000
        //   });
        //   this.isdisabled = false;
        //   return false;
      } else if (this.orderDate.trim() == "" && this.paymentId != 3) {
        Toast({
          message: "请选择刷卡时间",
          position: "bottom",
          duration: 2000
        });
        this.isdisabled = false;
        return false;
      } else if (this.orderAmount.trim() == "") {
        Toast({
          message: "请填写扣除杂费金额",
          position: "bottom",
          duration: 2000
        });
        this.isdisabled = false;
        return false;
      }
      // if (this.orderAmount <= 0) {
      //     Toast({
      //         message: "请填写正确的扣除杂费金额",
      //         position: "bottom",
      //         duration: 2000
      //     });
      //     this.isdisabled = false;
      //     return false;
      // } else
      else if (this.isopen && this.check_num.trim() == "") {
        Toast({
          message: "请输入验证码",
          position: "bottom",
          duration: 2000
        });
        this.isdisabled = false;
        return false;
      } else if (this.selected == "") {
        Toast({
          message: "请选择客户类型",
          position: "bottom",
          duration: 2000
        });
        this.isdisabled = false;
        return false;
      } else if (this.o_introduction.trim() == "") {
        Toast({
          message: "请填写备注",
          position: "bottom",
          duration: 2000
        });
        this.isdisabled = false;
        return false;
      } else {
        let load = this.loading("提交中");
        load.show();
        /* V1.8.7 */
        let extraType = "0";
        switch (this.zfpay) {
          case "现金":
            extraType = "1";
            break;
          case "分期":
            extraType = "2";
            break;
          case "线上收款":
            extraType = "3";
            break;
        }
        if (this.own_money == null) {
          this.own_money = 0;
        }
        if (this.stage_money == null) {
          this.stage_money = 0;
        }
        if (this.online_money == null) {
          this.online_money = 0;
        }
        /* V1.8.7 */
        let data = {
          //1.7迭代 新增三个字段 + 图片上传
          total_price: this.total_price - 0,
          // cash_allowancecash_allowance: this.cash_allowance - 0,
          // integral_allowance: this.integral_allowance - 0,
          img: this.img,

          // all_price: this.orderAmount - 0,
          all_price: this.jlzje,
          order_time: this.orderDate,
          payment: this.orderPaytype,
          user_name: this.o_username,
          user_phone: this.o_tel - 0,
          user_identify: this.o_identify, //用户身份证号
          user_remark: this.o_introduction,
          hospital_id: this.hospital,
          source: this.selected,
          type: this.isopen ? 1 : 0,
          verify: this.check_num,

          payment_id: this.paymentId,
          load_platform: this.loadPlatform,
          load_stage: this.loadStage,

          order_id: this.order_id,
          //咨询师id
          consultant_id: this.consultant_id,
          /* V1.8.7 */
          own_money: String(this.own_money),
          stage_money: String(this.stage_money),
          online_money: String(this.online_money),
          extra_type: String(extraType),
          payment_ids: this.paySelected,
          /* V1.8.8 */
          form_type: this.form_type,
          sales_type: String(this.sales_type),
          // v1.8.9
          code: String(this.code),
          gold_coin: String(this.gold_coin),
          platform_money: String(this.water_info.platform_money),
          is_whole_project: this.is_whole_project
        };
        console.log(JSON.stringify(data));
        this.axios
          .post("/api/butler/water_add", data)
          .then(msg => {
            this.isdisabled = false;
            load.hide();
            if (msg.data.code == 200) {
              Toast({
                message: "提交成功",
                position: "bottom",
                duration: 2000
              });
              this.order_sn = msg.data.data.order_sn;
              this.$router.push("/billdetail:" + this.order_sn);
            } else if (msg.data.code == 250) {
              Toast({
                message: "登录过期，请重新登陆",
                position: "bottom",
                duration: 2000
              });
              this.$router.push("/login");
              return false;
            } else {
              Toast({
                message: msg.data.msg,
                position: "bottom",
                duration: 2000
              });
            }
          })
          .catch(error => {
            load.hide();
            this.isdisabled = false;
            Toast({
              message: "请求失败，请稍后重试",
              position: "bottom",
              duration: 2000
            });
          });
      }
    },
    /**
     * 点击提交前的参数校验
     * @tips
     * 1. 由于前人没有使用ui的参数校验，这块代码看着很糟心
     * 2. 但我也不想全部改成组件的校验
     */
    bill_confirm() {
      if(this.form_type<0){
        Toast({
          message: `请选择报单类型`,
          position: "bottom",
          duration: 2000
        });
        return;
      }
      if (this.orderAmount - 0 + this.jlzje - 0 !== this.total_price - 0) {
        Toast({
          message: `请重填，奖励总金额+杂费必须等于消费总金额`,
          position: "bottom",
          duration: 2000
        });
        return;
      }
      let jez, xfz, xj, gxje, fkfs;
      // 录入的金额之和
      if (this.gold_coin && !this.water_info.platform_money) {
        jez =
          Number(this.online_money) +
          Number(this.own_money) +
          Number(this.stage_money) +
          Number(this.gold_coin) 
      }else if (this.gold_coin && this.water_info.platform_money) {
        jez =
          Number(this.online_money) +
          Number(this.own_money) +
          Number(this.stage_money) +
          Number(this.gold_coin) +
        Number(this.water_info.platform_money);
      }else{
         jez =
        Number(this.online_money) +
        Number(this.own_money) +
        Number(this.stage_money);
      }

      // 消费总金额
      xfz = Number(this.total_price);
      console.log(123, jez, xfz);
      // 消费总金额-扣除杂费金额
      xj = Number(this.total_price) - Number(this.orderAmount);
      //获取勾选付款方式填写的金额
      this.paymentIdOptions.forEach(e => {
        if (e.label == this.zfpay) {
          fkfs = e.label;
          gxje = this[e.id];
        }
      });
      // console.log( {
      //         //1.7迭代 新增三个字段 + 图片上传
      //         total_price: this.total_price - 0,
      //         // cash_allowancecash_allowance: this.cash_allowance - 0,
      //         // integral_allowance: this.integral_allowance - 0,
      //         img: this.img,

      //         all_price: this.orderAmount - 0,
      //         order_time: this.orderDate,
      //         payment: this.orderPaytype,
      //         user_name: this.o_username,
      //         user_phone: this.o_tel - 0,
      //         user_identify: this.o_identify, //用户身份证号
      //         user_remark: this.o_introduction,
      //         hospital_id: this.hospital,
      //         source: this.selected,
      //         type: this.isopen ? 1 : 0,
      //         verify: this.check_num,

      //         payment_id: this.paymentId,
      //         load_platform: this.loadPlatform,
      //         load_stage: this.loadStage,

      //         order_id: this.order_id,
      //         //咨询师id
      //         consultant_id: this.consultant_id
      //     })
      this.isdisabled = true;
      let xzjb = this.paySelected.join(" ");
      if (Number(xzjb) == 4 && Number(this.orderAmount) > 0) {
        Toast({
          message: `金币不允许支付杂费，请选择其余付款方式支付`,
          position: "bottom",
          duration: 2000
        });
        this.isdisabled = false;
        return false;
      } else if (
        this.accountOpenStatus == 2 &&
        this.form_type == 0 &&
        this.online_money > 0 &&
        Number(this.currentReimbursementRatio) == 0
      ) {
        Toast({
          message: `医院回款比率获取异常，请稍后再试`,
          position: "bottom",
          duration: 2000
        });
      } else if (
        this.accountOpenStatus == 2 &&
        this.form_type == 1 &&
        this.online_money > 0 &&
        Number(this.normalReimbursementRatio) == 0
      ) {
        Toast({
          message: `医院回款比率获取异常，请稍后再试`,
          position: "bottom",
          duration: 2000
        });
      } else if (this.accountOpenStatus != 2 && this.online_money > 0) {
        Toast({
          message: `当前医院未开户，不允许使用线上收款方式`,
          position: "bottom",
          duration: 2000
        });
      }
      // if(this.pay003&&!this.online_money){
      //     Toast({
      //         message: "已勾选付款方式金额为空，请填写后再提交",
      //         position: "bottom",
      //         duration: 2000
      //     });
      //     this.isdisabled = false;
      //     return false;
      // }else if(this.pay001&&!this.own_money){
      //     Toast({
      //         message: "已勾选付款方式金额为空，请填写后再提交",
      //         position: "bottom",
      //         duration: 2000
      //     });
      //     this.isdisabled = false;
      //     return false;
      // }else if(this.pay002&&!this.stage_money){
      //     Toast({
      //         message: "已勾选付款方式金额为空，请填写后再提交",
      //         position: "bottom",
      //         duration: 2000
      //     });
      //     this.isdisabled = false;
      //     return false;
      // }else
      else if (this.zfpaydiv && !this.zfpay) {
        Toast({
          message: "当前流水单存在杂费，请选择杂费付款方式",
          position: "bottom",
          duration: 2000
        });
        this.isdisabled = false;
        return false;
      } else if (jez != xfz) {
        Toast({
          message: "各付款方式金额之和不等于消费总金额，请重新输入",
          position: "bottom",
          duration: 2000
        });
        this.isdisabled = false;
        return false;
      }
      // if(gxje<xj){
      //     Toast({
      //         message: `${fkfs}填写的金额小于杂费金额，请重新输入`,
      //         position: "bottom",
      //         duration: 2000
      //     });
      //     this.isdisabled = false;
      //     return false;
      // }
      else if (gxje < this.orderAmount) {
        Toast({
          message: `${fkfs}填写的金额小于杂费金额，请重新输入`,
          position: "bottom",
          duration: 2000
        });
      } else if (this.hospital == "") {
        Toast({
          message: "请选择医院",
          position: "bottom",
          duration: 2000
        });
        this.isdisabled = false;
        return false;
      } else if (this.o_username.trim() == "") {
        Toast({
          message: "请填写客户姓名",
          position: "bottom",
          duration: 2000
        });
        this.isdisabled = false;
        return false;
      } else if (this.o_tel.trim() == "") {
        Toast({
          message: "请填写客户手机号",
          position: "bottom",
          duration: 2000
        });
        this.isdisabled = false;
        return false;
        // } else if (this.orderPaytype.trim() == "") {
        //   Toast({
        //     message: "请填写付款方式",
        //     position: "bottom",
        //     duration: 2000
        //   });
        //   this.isdisabled = false;
        //   return false;

        // } else if (this.paymentId == 2 && this.loadStage == 0) {
        //   Toast({
        //     message: "请输入分期期数",
        //     position: "bottom",
        //     duration: 2000
        //   });
        //   this.isdisabled = false;
        //   return false;
      } else if (this.orderDate.trim() == "" && this.paymentId != 3) {
        Toast({
          message: "请选择刷卡时间",
          position: "bottom",
          duration: 2000
        });
        this.isdisabled = false;
        return false;
      } else if (this.orderAmount.trim() == "") {
        Toast({
          message: "请填写扣除杂费金额",
          position: "bottom",
          duration: 2000
        });
        this.isdisabled = false;
        return false;
      } else if (this.isopen && this.check_num.trim() == "") {
        Toast({
          message: "请输入验证码",
          position: "bottom",
          duration: 2000
        });
        this.isdisabled = false;
        return false;
      } else if (this.selected == "") {
        Toast({
          message: "请选择客户类型",
          position: "bottom",
          duration: 2000
        });
        this.isdisabled = false;
        return false;
      } else if (this.o_introduction.trim() == "") {
        Toast({
          message: "请填写备注",
          position: "bottom",
          duration: 2000
        });
        this.isdisabled = false;
        return false;

        //管家1.7新增四个字段
      } else if (this.total_price.trim() == "") {
        Toast({
          message: "请填写消费总金额",
          position: "bottom",
          duration: 2000
        });
        this.isdisabled = false;
        return false;

        //走了线上收款 我们不校验图片必填
      } else if (
        !(
          this.paySelected.length == 1 && this.paySelected.indexOf("3") != -1
        ) &&
        this.img.trim() == "" &&
        this.paymentId != 3
      ) {
        Toast({
          message: "请上传图片",
          position: "bottom",
          duration: 2000
        });
        this.isdisabled = false;
        return false;
      } else {
        console.log("扣除杂费金额为", this.total_price);
        console.log("扣除成本金额为", this.orderAmount);

        //检测 几个金额之间的关系！！
        let tmp_orderAmount = parseFloat(this.orderAmount);
        let tmp_total_price = parseFloat(this.total_price);

        if (tmp_orderAmount > tmp_total_price) {
          Toast({
            message: "扣除杂费金额 不能大于 消费总金额",
            position: "bottom",
            duration: 2000
          });
          this.isdisabled = false;
          return false;
        }

        this.confirm = true;
      }
    },
    selectTime(date, selectedVal, selectedText) {
      if (!this.dateTimePicker) {
        this.dateTimePicker = this.$createDatePicker({
          title: "请选择刷卡时间",
          min: new Date(new Date().getFullYear(), 0, 1, 0, 0, 0),
          max: new Date(new Date().getFullYear(), 11, 31, 23, 59, 59),
          value: new Date(),
          columnCount: 6,
          onSelect: (date, selectedVal, selectedText) => {
            let timeArr = selectedVal,
              tostring;
            timeArr[1] = timeArr[1] - 0 < 0 ? "0" + timeArr[1] : timeArr[1];
            timeArr[2] = timeArr[2] < 0 ? "0" + timeArr[2] : timeArr[2];
            timeArr[3] = timeArr[3] < 0 ? "0" + timeArr[3] : timeArr[3];
            timeArr[4] = timeArr[4] < 0 ? "0" + timeArr[4] : timeArr[4];
            timeArr[5] = timeArr[5] < 0 ? "0" + timeArr[5] : timeArr[5];
            tostring =
              timeArr[0] +
              "-" +
              timeArr[1] +
              "-" +
              timeArr[2] +
              " " +
              timeArr[3] +
              ":" +
              timeArr[4] +
              ":" +
              timeArr[5];
            this.orderDate = tostring;
          },
          onCancel: this.cancelTime
        });
      }
      this.dateTimePicker.show();
    },
    cancelTime() {
      this.orderDate = "";
    },
    getHospitalList() {
      this.order_sn = location.hash.split(":")[1];
      var arr = JSON.parse(localStorage.hospital_list);
      arr.forEach(el => {
        el.value = el.id;
        el.text = el.name;
      });
      this.hospital_list = arr;
      console.log(1111,this.hospital_list);
    },
    get_service() {
      this.server_username = "";
      this.server_name = "";
      let load = this.loading("请求中");
      load.show();
      this.axios
        .post("api/butler/getServer", {
          username: this.o_tel
        })
        .then(response => {
          load.hide();
          let res = response.data;
          console.log(res);
          if (res.code == 200) {
            this.server_username = res.data.server_username;
            this.server_name = res.data.server_name;
            this.credit_all = res.data.user_credit;
          } else {
            Toast({
              message: res.msg,
              position: "bottom",
              duration: 2000
            });
          }
        })
        .catch(error => {
          load.hide();
          console.log(error);

          Toast({
            message: "请求失败，请稍后重试",
            position: "bottom",
            duration: 2000
          });
        });
    },
    toggle_status() {
      console.log(123);
    },
    change_money() {
      this.credit =
        this.orderAmount - 0 < this.credit_all - 0
          ? this.orderAmount - 0
          : this.credit_all - 0;
      this.pay_num = this.orderAmount - 0 - this.credit;
      this.jlzje = this.total_price - this.orderAmount;
      if (this.jlzje >= 0) {
        this.jlzje = this.total_price - this.orderAmount;
      } else {
        this.jlzje = 0;
      }
      console.log(this.jlzje);
    },
    get_check() {
      if (this.o_tel.trim() == "") {
        Toast({
          message: "请填写客户手机号",
          position: "bottom",
          duration: 2000
        });
        this.isdisabled = false;
        return false;
      } else {
        if (this.num < 60) {
          return false;
        }
        let loading = this.loading("请求中...", 60000);
        loading.show();
        this.axios
          .post("api/send/msg", {
            type: 1009,
            username: this.o_tel,
            credit: this.credit
          })
          .then(msg => {
            loading.hide();
            let res = msg.data;
            if (msg.data.code == 200) {
              Toast({
                message: "请求成功，请注意查收短信",
                position: "bottom",
                duration: 2000
              });
              timer = setInterval(() => {
                this.num--;
                this.btn_msg = `${this.num}秒后可重新发送`;
                if (this.num < 1) {
                  clearInterval(timer);
                  this.num = 60;
                  this.btn_msg = "获取验证码";
                }
              }, 1000);
            } else if (msg.data.code == 250) {
              Toast({
                message: "登录过期，请重新登陆",
                position: "bottom",
                duration: 2000
              });
              this.$router.push("/login");
              return false;
            } else {
              Toast({
                message: msg.data.msg,
                position: "bottom",
                duration: 2000
              });
            }
          })
          .catch(error => {
            console.log(error);
            Toast({
              message: "请求错误，请稍后重试",
              position: "bottom",
              duration: 2000
            });
          });
      }
    },

    //图片上传相关操作
    filesAddedOrder(files) {
      //消费凭证
      let hasIgnore = false;
      const maxSize = 20 * 1024 * 1024; // 20M
      for (let k in files) {
        const file = files[k];
        if (file.size > maxSize) {
          file.ignore = true;
          hasIgnore = true;
        }
      }
      hasIgnore &&
        this.$createToast({
          type: "warn",
          time: 1000,
          txt: "图片上传失败，不能大于20M"
        }).show();
    },
    fileSuccessOrder(file) {
      this.img += file.response.data.url + "#";
    },
    //图片上传 手动删除
    fileRemovedOrder(file) {
      let curImg = this.img;
      let removeFileUrl = file.response.data.url;

      if (curImg && removeFileUrl) {
        let picArray = curImg.split("#");
        if (picArray) {
          console.log("删除前的数组为", picArray);
          let index = picArray.indexOf(removeFileUrl);
          picArray.splice(index, 1);
          console.log("删除后的数组为", picArray);

          curImg = picArray.join("#");
          console.log("图片上传地址删除后", curImg);
          this.img = curImg;
        }
      }
    }
  },

  watch: {
    // 监听付款方式 修改贷款平台默认值 （4.18隐藏掉）
    // paymentId: function(newVal,oldVal){
    //   console.log(newVal +"---"+oldVal);
    //   if (newVal == 2) {
    //     this.loadPlatform = 1;
    //     this.orderPaytype = "分期";
    //   }
    //   if (newVal == 1) {
    //     this.loadStage = 0;
    //     this.orderPaytype = "自费";
    //   }
    // }
    form_type(e) {
      if (e == 0) {
        this.form_type_tf = true;
       console.log(this.form_type_tf)
      } else {
        this.form_type_tf = false;
       console.log(this.form_type_tf)
      }
    },
    sales_type(e) {
      if (e == "2020") {
        this.saleFlag = true;
      } else {
        this.saleFlag = false;
      }
    },
    // 付款方式判断
    paySelected(e) {
      this.zfpay = null;
      if (e.indexOf("1") != -1) {
        this.pay001 = true;
      } else {
        this.pay001 = false;
      }
      if (e.indexOf("2") != -1) {
        this.pay002 = true;
      } else {
        this.pay002 = false;
      }
      if (e.indexOf("3") != -1) {
        this.pay003 = true;
      } else {
        this.pay003 = false;
      }
      if (e.indexOf("4") != -1) {
        this.pay004 = true;
      } else {
        this.pay004 = false;
      }
    },
    // 判断付款方式勾选进行数据重置
    pay001(e) {
      if (!e) {
        this.own_money = null;
      }
    },
    pay002(e) {
      if (!e) {
        this.stage_money = null;
      }
    },
    pay003(e) {
      if (!e) {
        this.online_money = null;
      }
    },
    // 判断杂费金额是否大于0（杂费金额=消费总金额-扣除杂费金额）
    total_price(e) {
      setTimeout(() => {
        // if(Number(this.total_price) - Number(this.orderAmount) > 0){
        //     this.zfpaydiv = true
        // }else{
        //     this.zfpaydiv = false
        // }
        if (Number(this.orderAmount) > 0) {
          this.zfpaydiv = true;
        } else {
          this.zfpaydiv = false;
        }
      }, 800);
    },
    orderAmount(e) {
      setTimeout(() => {
        // if(Number(this.total_price) - Number(this.orderAmount) > 0){
        //     this.zfpaydiv = true
        // }else{
        //     this.zfpaydiv = false
        // }
        if (Number(this.orderAmount) > 0) {
          this.zfpaydiv = true;
        } else {
          this.zfpaydiv = false;
        }
      }, 800);
    },
    cancelChecked(){
      console.log(99999999)
    }
  },

  mounted() {
    this.axios.defaults.baseURL = api;
    this.getHospitalList();
    document.title = "创建流水单";

    let url_data = location.hash.split(":")[1];
    this.order_id = url_data.split("_")[0];

    //获取预约单的信息
    this.getOrderInfo();
  }
};
</script>
<style lang="less" scoped>
.layout_createdBill {
  width: 100%;
  height: 100%;
  overflow: auto;
  font-size: 17px;
  color: #666;
  text-align: center;
}
.mask {
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.30091);
  position: absolute;
  top: 0;
  left: 0;
  z-index: 100;
  .content {
    width: 251px;
    background: rgba(255, 255, 255, 1);
    border-radius: 4px;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    .header {
      font-size: 16px;
      font-family: "PingFangSC-Medium";
      font-weight: 500;
      line-height: 52px;
      color: rgba(68, 68, 68, 1);
      text-align: center;
      border-bottom: 1px solid rgba(245, 245, 245, 1);
    }
    .main {
      padding-left: 15px;
      margin-top: 15px;
      margin-bottom: 5px;
      text-align-last: left;

      .tip {
        font-size: 14px;
        margin-bottom: 14px;
        padding-right: 10px;
        color: grey;
        font-weight: 900;
      }
      .item {
        font-size: 14px;
        font-family: "PingFangSC-Regular";
        font-weight: 400;
        color: rgba(68, 68, 68, 1);
        line-height: 20px;
        // &:nth-of-type(2n) {
        //   margin-bottom: 15px;
        // }
      }
      .item-line {
        margin-bottom: 15px;
      }
    }
    .bottom {
      width: 100%;
      font-size: 16px;
      font-family: "PingFangSC-Regular";
      font-weight: 400;
      color: rgba(255, 0, 0, 1);
      line-height: 52px;
      text-align: center;
      border-top: 1px solid rgba(245, 245, 245, 1);
    }
  }
}
.mint-field {
  border-bottom: 1px solid rgba(204, 204, 204, 0.3242) !important;
}
.row {
  min-height: 48px;
  line-height: 48px;
  background-color: #fff;
  text-align: left;
  padding-left: 15px;
  border-bottom: 1px solid rgba(204, 204, 204, 0.3242);
  position: relative;
}
.border_no {
  border-bottom: none !important;
}
.border_yes {
  padding-bottom: 13px;
  border-bottom: 1px solid rgba(204, 204, 204, 0.3242);
}
.row input {
  height: 46px;
  margin-bottom: 2px;
  background-color: #fff;
}
/* 选择器样式 */
.cube-btn {
  height: 48px !important;
  line-height: 20px !important;
  background: #fff !important;
  color: #666 !important;
  text-align: left !important;
  padding: 0 !important;
  font-size: 17px;
  z-index: 99;
}
.ivu-icon {
  position: absolute !important;
  right: 4% !important;
  bottom: 25% !important;
}
.cube-toast-icon {
  height: 36px !important;
}
.text {
  text-align: left;
  letter-spacing: 18px;
  padding: 0 15px;
}
.text span {
  height: 50px;
  line-height: 50px;
}
.mint-field.is-textarea {
  border: 1px solid rgba(204, 204, 204, 0.2018) !important;
}
</style>

<style lang="less">
.layout_createdBill {
  .select-icon {
    display: block;
    font-size: 20px;
    position: absolute !important;
    right: 20px !important;
    top: 50% !important;
    transform: translateY(-50%) !important;
    z-index: 99;
  }
  .orderDate {
    width: 50%;
    height: 50px;
    line-height: 50px;
    display: block;
    position: absolute;
    top: 0;
    left: 110px;
  }
  .tip {
    color: #ccc;
    margin-top: -25px;
  }
  .cube-select {
    border: none;
    display: inline-block;
    width: 70%;
    .cube-select-icon {
      display: none !important;
    }
    &::after {
      border: none;
    }
  }
  .cube-radio-group[data-horz="true"]::after {
    border: none !important;
  }
  .border-right-1px {
    border-right: 0 !important;
  }
  .type {
    display: flex;
    .cube-radio-group {
      min-width: 60%;
    }
  }
  .cube-radio_selected .cube-radio-ui {
    background-color: rgba(255, 137, 169, 1);
  }

  .credit {
    .cube-switch {
      position: absolute;
      top: 50%;
      right: 15px;
      transform: translateY(-50%);
    }
    .cube-switch .cube-switch-input:checked + .cube-switch-ui {
      background-color: #09bb07;
      border-color: #09bb07;
    }
  }
  .check_num {
    .get-msg {
      height: 32px;
      line-height: 32px;
      padding: 0 15px;
      text-align: center;
      border-radius: 16px;
      border: 1px solid rgba(204, 204, 204, 1);
      font-size: 14px;
      font-family: "PingFangSC-Regular";
      font-weight: 400;
      color: rgba(102, 102, 102, 1);
      position: absolute;
      right: 15px;
      top: 50%;
      transform: translateY(-50%);
    }
  }

  .uploadMoudle {
    margin-top: 10px;
    background-color: #fff;
    padding: 13px 15px;
  }
  .uploadMoudle p {
    font-size: 16px;
    text-align: left;
    margin-bottom: 13px;
  }

  .jiange {
    width: 100%;
    height: 10px;
    background-color: #f4f4f4;
  }

  .aicon {
    width: 70px;
    height: 30px;
    background-color: #fca3bb;
    border-radius: 0 0 10px 0;
    color: #fff;
    line-height: 30px;
    text-align: center;
  }
}
</style>
<style lang="less" scope>
.paddingsx {
  padding: 4px 0;
}
.cube-checkbox {
  padding: 0 !important;
}
.cube-checkbox_checked .cube-checkbox-ui i {
  color: #ff89a9 !important;
}
.cube-radio-group[data-horz="true"] .cube-radio-wrap {
  justify-content: flex-start !important;
}
.jybspan {
  position: absolute;
  top: 0;
  right: 0;
}
.relative {
  position: relative;
}
.yzmdiv {
  position: relative;
  margin: 6px 0;
}
.yzm {
  background: rgb(67, 189, 204);
  position: absolute;
  width: 100px;
  text-align: center;
  top: 0;
  right: 20px;
  color: white;
  border-radius: 4px;
  height: 40px;
  display: inline-block;
  font-size: 14px;
  padding: 0 10px;
  line-height: 40px;
}
.disableds {
  pointer-events: none;
}
.num {
  margin: 0 25px;
  height: 35px;
  background: rgba(245, 245, 245, 1);
  border-radius: 2px;
  line-height: 35px;
  padding: 0 10px;
}
</style>
